package gk.example.view;

import gk.example.adapter.MainMenuAdapter;
import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.PopupWindow;

import com.example.gkdate.R;

public class MainMenu extends PopupWindow {
	private Context mContext;

	public MainMenu(Context context) {
		mContext = context;
		initView();
	}

	public interface OnMainMenuClickListener {
		void onMainMenuItemClick(int position);
	}

	OnMainMenuClickListener mOnMainMenuClickListener;

	public void setOnMainMenuClickListener(
			OnMainMenuClickListener onMainMenuClickListener) {
		mOnMainMenuClickListener = onMainMenuClickListener;

	}

	@SuppressWarnings("deprecation")
	public void initView() {
		View layout = LayoutInflater.from(mContext).inflate(
				R.layout.drop_down_menu_main, null);
		setContentView(layout);
		setWidth(400);
		setHeight(680);
		this.setFocusable(true);
		this.setOutsideTouchable(true);
		this.update();
		this.setBackgroundDrawable(new BitmapDrawable());
		ListView lv_drop_down_menu_main = (ListView) layout
				.findViewById(R.id.lv_drop_down_menu_main);
		lv_drop_down_menu_main.setAdapter(new MainMenuAdapter(mContext));
		lv_drop_down_menu_main
				.setOnItemClickListener(new OnItemClickListener() {
					@Override
					public void onItemClick(AdapterView<?> parent, View view,
							int position, long id) {
						// TODO Auto-generated method stub
						if (mOnMainMenuClickListener != null) {
							mOnMainMenuClickListener
									.onMainMenuItemClick(position);
						}
						dismiss();
					}
				});
	}
	
}
